#include "PyProMdl.h"
#include "BindFunction.h"
#include <ProMdl.h>

using namespace pyBind;

static PyObject* PyProMdlInit  ( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_in|_val,ProNameTag>,Ag<_in|_val>,Ag<_ret|_adr,ProMdlTag>>(ProMdlInit,self,args);
}

static PyObject* PyProMdlRename( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>,Ag<_in|_val,ProNameTag> >(ProMdlRename,self,args);
}	

static PyObject* PyProMdlCopy( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>,Ag<_in|_val,ProNameTag>,Ag<_ret|_adr,ProMdlTag> >(ProMdlCopy,self,args);
}

static PyObject* PyProMdlSave( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>>(ProMdlSave,self,args);
}

static PyObject* PyProMdlBackup( PyObject *self, PyObject *args )
{
	PyProMdl * mdl = (PyProMdl *)self;
	PyObject * pypath;
	if(!PyArg_ParseTuple(args,"U:MdlBackup", 
		&pypath))
		return NULL;

	int size = PyUnicode_GET_SIZE(pypath);
	wchar_t* valstr = PyUnicode_AS_UNICODE(pypath);
	ProMdldata data;
	wcscpy_s(data.path,size+1,valstr);

	ProErr err = ProMdlBackup(mdl->mdl,&data);
	if(PRO_TK_NO_ERROR == err)
	{
		Py_RETURN_NONE;
	}
	else
	{
		PyErr_SetObject((PyObject *)&pyProErrorType,PyLong_FromLong(err));
		return NULL;
	}
}	

static PyObject* PyProMdlRetrieve( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_in|_val,WStringTag>,Ag<_in|_val>,Ag<_ret|_adr,ProMdlTag>>(ProMdlRetrieve,self,args);
}


static PyObject* PyProMdlLoad( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_in|_val,WStringTag>,Ag<_in|_val>,Ag<_in|_val>,Ag<_ret|_adr,ProMdlTag>>(ProMdlLoad,self,args);
}

static PyObject* PyProMdlErase( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>>(ProMdlErase,self,args);
}

static PyObject* PyProMdlEraseAll( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>>(ProMdlEraseAll,self,args);
}
static PyObject* PyProMdlEraseNotDisplayed( PyObject *self, PyObject *args )
{
	return PyFun(ProMdlEraseNotDisplayed,self,args);
}

static PyObject* PyProMdlDelete( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>>(ProMdlDelete,self,args);
}

static PyObject* PyProMdlfileCopy( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_in|_val>,Ag<_in|_val,WStringTag>,Ag<_in|_val,WStringTag>>(ProMdlfileCopy,self,args);
}

static PyObject* PyProMdlDisplay( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>>(ProMdlDisplay,self,args);
}

static PyObject* PyProMdlNameGet( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>,Ag<_ret|_val,ProNameTag> >(ProMdlNameGet,self,args);
}


static PyObject* PyProMdlDataGet( PyObject *self, PyObject *args )
{
	PyProMdl * mdl = (PyProMdl *)self;

	ProMdldata data;
	memset(&data,0,sizeof(ProMdldata));
	ProErr err = ProMdlDataGet(mdl->mdl,&data);
	if(PRO_TK_NO_ERROR == err)
	{
		return Py_BuildValue("(uuuuii)",data.name,data.type,data.path,data.device,data.version,data.subclass);
	}
	else
	{
		PyErr_SetObject((PyObject *)&pyProErrorType,PyLong_FromLong(err));
		return NULL;
	}
}

static PyObject* PyProMdlCurrentGet( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_ret|_adr,ProMdlTag>>(ProMdlCurrentGet,self,args);
}	

static PyObject* PyProMdlModificationVerify( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>,Ag<_ret|_adr> >(ProMdlModificationVerify,self,args);
}

static PyObject* PyProMdlTypeGet( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>,Ag<_ret|_adr> >(ProMdlTypeGet,self,args);
}
static PyObject* PyProMdlSubtypeGet( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>,Ag<_ret|_adr> >(ProMdlSubtypeGet,self,args);
}
static PyObject* PyProMdlIdGet( PyObject *self, PyObject *args )
{
	return PyFun<Ag<_this|_val,ProMdlTag>,Ag<_ret|_adr> >(ProMdlIdGet,self,args);
}




static PyMethodDef ProMdl_methods[] = {
	{"Init", PyProMdlInit, METH_VARARGS|METH_STATIC,"Init ProMdl."},
	{"Rename", PyProMdlRename, METH_VARARGS,"Rename ProMdl."},
	{"Copy", PyProMdlCopy, METH_VARARGS,"Copy ProMdl."},
	{"Save", PyProMdlSave, METH_VARARGS,"Save ProMdl."},
	{"Backup", PyProMdlBackup, METH_VARARGS,"Backup ProMdl."},
	{"Retrieve", PyProMdlRetrieve, METH_VARARGS|METH_STATIC,"Retrieve ProMdl."},
	{"Load", PyProMdlLoad, METH_VARARGS|METH_STATIC,"Load ProMdl."},
	{"Erase", PyProMdlErase, METH_VARARGS,"Erase ProMdl."},
	{"EraseAll", PyProMdlEraseAll, METH_VARARGS,"EraseAll ProMdl."},
	{"EraseNotDisplayed", PyProMdlEraseNotDisplayed, METH_VARARGS|METH_STATIC,"EraseNotDisplayed ProMdl."},
	{"Delete", PyProMdlDelete, METH_VARARGS,"Delete ProMdl."},
	{"fileCopy", PyProMdlfileCopy, METH_VARARGS|METH_STATIC,"fileCopy."},
	{"Display", PyProMdlDisplay, METH_VARARGS,"Display ProMdl."},
	{"NameGet", PyProMdlNameGet, METH_VARARGS,"NameGet."},
	{"DataGet", PyProMdlDataGet, METH_VARARGS,"DataGet."},
	{"Current", PyProMdlCurrentGet, METH_VARARGS|METH_STATIC,"Current."},
	{"ModificationVerify", PyProMdlModificationVerify, METH_VARARGS,"ProMdl ModificationVerify."},
	//ProMdlVerstampGet
	{"TypeGet", PyProMdlTypeGet, METH_VARARGS,"ProMdl TypeGet."},
	{"SubtypeGet", PyProMdlSubtypeGet, METH_VARARGS,"ProMdl SubtypeGet."},
	{"IdGet", PyProMdlTypeGet, METH_VARARGS,"ProMdl IdGet."},
	 //ProMdlDeclaredList
	 //ProMdlDependenciesList

	{NULL}  /* Sentinel */
};

PyTypeObject PyProMdlType = {
	PyVarObject_HEAD_INIT(NULL, 0)
	"Protk.Mdl",             /* tp_name */
	sizeof(PyProMdl),			/* tp_basicsize */
	0,                         /* tp_itemsize */
	0,                         /* tp_dealloc */
	0,                         /* tp_print */
	0,                         /* tp_getattr */
	0,                         /* tp_setattr */
	0,                         /* tp_reserved */
	0,                         /* tp_repr */
	0,                         /* tp_as_number */
	0,                         /* tp_as_sequence */
	0,                         /* tp_as_mapping */
	0,                         /* tp_hash  */
	0,                         /* tp_call */
	0,                         /* tp_str */
	0,                         /* tp_getattro */
	0,                         /* tp_setattro */
	0,                         /* tp_as_buffer */
	Py_TPFLAGS_DEFAULT,        /* tp_flags */
	"ProMdl objects",           /* tp_doc */
	0,		               /* tp_traverse */
	0,		               /* tp_clear */
	0,		               /* tp_richcompare */
	0,		               /* tp_weaklistoffset */
	0,		               /* tp_iter */
	0,		               /* tp_iternext */
	ProMdl_methods,             /* tp_methods */
	0,             /* tp_members */
	0,                         /* tp_getset */
	0,                         /* tp_base */
	0,                         /* tp_dict */
	0,                         /* tp_descr_get */
	0,                         /* tp_descr_set */
	0,                         /* tp_dictoffset */
	0,      /* tp_init */
	0,                         /* tp_alloc */
	0,                 /* tp_new */

};



int PyInit_ProMdl(  PyObject* m )
{
	PyType_Ready(&PyProMdlType);
	Py_INCREF(&PyProMdlType);
	return PyModule_AddObject(m, "Mdl", (PyObject *)&PyProMdlType);
}